package com.qf.listener;


import com.qf.utils.DruidUtils;
import com.qf.utils.LoadConfigUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 该类的目的就是用来加载应用的资源
 */
@WebListener
public class InitSourceListener implements ServletContextListener {

    //初始化调用

    /**
     * 通过(sce.getServletContext().getInitParameter() 取的是在 web.xml中配置：
     *   <context-param>
     *         <param-name>name</param-name>
     *         <param-value>lucy</param-value>
     *   </context-param>
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //初始化数据库连接池
        String druidConfigFileName = sce.getServletContext().getInitParameter("druidConfigFile");
        DruidUtils.initDataSource(druidConfigFileName);
        //初始化文件路径配置
        String fileUrlConfigFile = sce.getServletContext().getInitParameter("fileUrlConfigFile");
        LoadConfigUtils.initConfigFile(fileUrlConfigFile);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
